package com.easydata.agent.service;


import com.easydata.agent.exceptions.TaskException;
import com.easydata.libPlugin.core.AbstractDAGNode;
import org.pf4j.PluginManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class PluginService {
    @Autowired
    PluginManager manager;

    public AbstractDAGNode getByName(String name) throws TaskException {
        List<AbstractDAGNode> extensions = manager.getExtensions(AbstractDAGNode.class);

        if (extensions == null || extensions.isEmpty()) {
            throw new TaskException(-1, "plugin is not exist");
        }

        AbstractDAGNode baseDAGNode = extensions.stream().filter(n -> n.name().equals(name)).findFirst().orElse(null);
        return baseDAGNode;
    }
}